class Solution {
public:
    //满足，  返回i
   //否则 如果(i)>(i+1)左走（搜索区间[l,i-1]），左边必有峰值  i<(i+1)右走[i+1,n-1]，必有峰值
    pair<int,int> compare(vector<int> a,int index){
        if (index==a.size()||index==-1) return {0,0};
        else return {1,a[index]};
    }

    int findPeakElement(vector<int>& nums) {
        int begin = 0,end = nums.size()-1;
        if (end==0) return 0;
        int res;
        while(begin<=end){
            int mid = (end-begin)/2 + begin;
            if (compare(nums,mid)>compare(nums,mid+1)&&compare(nums,mid)>compare(nums,mid-1)){
                res = mid;break;
            }
            else if (compare(nums,mid)>compare(nums,mid+1)){
                end = mid - 1;
            }else  begin = mid + 1; 
        }
        return res;
    }
};